package com.yinhe.module.cjl;

import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.YhRiskNotification;
import com.yinhe.system.service.IYhRiskNotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 风险告知单Controller
 *
 * @author yinhe
 * @date 2022-07-13
 */
@RestController
@RequestMapping("/module/cjl/inform")
public class CjlRiskInformController extends BaseController{
    @Autowired
    private IYhRiskNotificationService yhRiskNotificationService;

    /**
     * 查询风险告知单列表
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:inform:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhRiskNotification yhRiskNotification)
    {
        startPage();
        List<YhRiskNotification> list = yhRiskNotificationService.selectYhRiskNotificationList(yhRiskNotification);
        return getDataTable(list);
    }

    /**
     * 导入风险告知单列表
     */
    @Log(title = "风险告知单", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('module:cjl:inform:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YhRiskNotification> util = new ExcelUtil<YhRiskNotification>(YhRiskNotification.class);
        List<YhRiskNotification> riskNotificationList = util.importExcel(file.getInputStream());
        String message = yhRiskNotificationService.importRiskNotification(riskNotificationList, updateSupport);
        return AjaxResult.success(message);
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YhRiskNotification> util = new ExcelUtil<YhRiskNotification>(YhRiskNotification.class);
        util.importTemplateExcel(response, "风险告知单数据");
    }

    /**
     * 导出风险告知单列表
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:inform:export')")
    @Log(title = "风险告知单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhRiskNotification yhRiskNotification)
    {
        List<YhRiskNotification> list = yhRiskNotificationService.selectYhRiskNotificationList(yhRiskNotification);
        ExcelUtil<YhRiskNotification> util = new ExcelUtil<YhRiskNotification>(YhRiskNotification.class);
        util.exportExcel(response, list, "风险告知单数据");
    }

    /**
     * 获取风险告知单详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:inform:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhRiskNotificationService.selectYhRiskNotificationById(id));
    }

    /**
     * 新增风险告知单
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:inform:add')")
    @Log(title = "风险告知单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhRiskNotification yhRiskNotification)
    {
        long represent = Long.parseLong(yhRiskNotification.getRepresentativeOffice());
        yhRiskNotification.setDeptId(represent);
        return toAjax(yhRiskNotificationService.insertYhRiskNotification(yhRiskNotification));
    }

    /**
     * 修改风险告知单
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:inform:edit')")
    @Log(title = "风险告知单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhRiskNotification yhRiskNotification)
    {
        long represent = Long.parseLong(yhRiskNotification.getRepresentativeOffice());
        yhRiskNotification.setDeptId(represent);
        return toAjax(yhRiskNotificationService.updateYhRiskNotification(yhRiskNotification));
    }

    /**
     * 删除风险告知单
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:inform:remove')")
    @Log(title = "风险告知单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhRiskNotificationService.deleteYhRiskNotificationByIds(ids));
    }
}
